import Axios from 'axios'
import Vue from 'vue'

import {
    ToastPlugin
} from 'vux'
Vue.use(ToastPlugin)

const axios = Axios.create({
    // baseURL: 'http://localhost:8080/LiveManager/api/',
    // baseURL: 'http://gyx.tunnel.qydev.com/LiveManager/api/',
    // baseURL: 'http://192.168.0.109:8080/LiveManager/api/',
    // baseURL:'http://baas.ievent.cn/LiveManager/api/',
    baseURL: 'http://weixin.ls0533.com'
})
Vue.config.productionTip = false

Vue.prototype.$http = axios
// http request拦截器
axios.interceptors.request.use(function (config) {
    let token = window.store.get('token')
    if (token) {
        config.headers.Authorization = token
    }
    return config
},
    function (error) {
        return Promise.reject(error)
    }
)
// http response拦截器
// axios.interceptors.response.use(
//   function (response) {
//       return response
//   },
//   function (error) {
//       alert('网络异常,请稍后再试!')
//       return Promise.reject(error)
//   }
//   )
axios.interceptors.response.use((response) => {
    return response
}, function (error) {
    if (error.response.status === 401) {
        window.location = '/login'
    } else {
        return Promise.reject(error)
    }
})
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
// var IEVENT_BASE_URL = 'http://localhost:8084/IeventManager/'
// var IEVENT_BASE_URL = 'http://gyx.tunnel.qydev.com/IeventManager/'
// var IEVENT_BASE_URL = 'http://testsys.ievent.cn:808/IeventManager/'
const api = {
    bsURL: 'https://weixin.ls0533.com'
}

export default api
